package com.mall.controller;

import com.mall.entity.SpuInfo;
import com.mall.service.impl.SearchSpulmpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/search")
public class SearchController {
    @Autowired
    private SearchSpulmpl searchSpulmpl;

    @GetMapping("/cat")
    public List<SpuInfo> searchCat(Integer parentid, Integer start , Integer pagesize,String sort, HttpServletResponse response){
            List<SpuInfo> spuInfos = searchSpulmpl.searchByCat(parentid, start, pagesize,sort);
            response.setHeader("count",searchSpulmpl.countCat(parentid).toString());
            return spuInfos;
    }
    @GetMapping("/key")
    public List<SpuInfo> searchKeyWord(String  keyword,Integer start , Integer pagesize,String sort,HttpServletResponse response){
        List<SpuInfo> spuInfos = searchSpulmpl.searchByKeyWord(keyword, start, pagesize,sort);
        response.setHeader("count",searchSpulmpl.countKey(keyword).toString());
        return spuInfos;
    }
}
